﻿using BLL;
using Model;
using System;

namespace Thksoft.BusinessExpansion.Process
{
    public partial class EditBlock : BaseUI.BasePage
    {
        private Lc_BlockBLL lbb = new Lc_BlockBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    //((MainCont)Master).GetSite.
                    IfEdit.Value = "0";
                    lbltitle.InnerText = "添\t加\t模\t块";
                }
                else
                {
                    IfEdit.Value = "1";
                    lbltitle.InnerText = "模\t块\t编\t辑";
                    decimal moduleKey = Convert.ToDecimal(Request.QueryString["ID"]);
                    var entity = lbb.GetEntity(moduleKey);
                    ModuleName.Text = entity.C_BLOCK_NAME;
                    ModulePath.Text = entity.C_BLOCK_DEPATH;
                    ModuleKey.Value = entity.N_BLOCK_ID.ToString().Trim();
                    ModuleRemark.Text = entity.REMARK;
                }
            }
        }

        protected void SaveClick(object sender, EventArgs e)
        {
            if (IfEdit.Value == "1")
            {
                decimal moduleKey = Convert.ToDecimal(ModuleKey.Value);
                var moduleName = ModuleName.Text.Trim();
                var modulePath = ModulePath.Text.Trim();
                var moduleRemark = ModuleRemark.Text;
                if (moduleName == "")
                {
                    MessageBox.Show(this, "【温馨提醒】请输入模块名称");
                    return;
                }
                if (modulePath == "")
                {
                    MessageBox.Show(this, "【温馨提醒】请输入模块路径");
                    return;
                }
                var entity = lbb.GetEntity(moduleKey);
                entity.C_BLOCK_NAME = moduleName;
                entity.C_BLOCK_DEPATH = modulePath;
                //entity.C_BLOCK_NAME = CurrentUserName;
                entity.REMARK = moduleRemark;
                var c = lbb.UPDATE(entity, CurrentUserName);
                if (c > 0)
                {
                    MessageBox.Show(this, "【温馨提醒】修改成功");
                }
                else
                {
                    MessageBox.Show(this, "【温馨提醒】修改失败！");
                }
            }
            else
            {
                var moduleName = ModuleName.Text.Trim();
                var modulePath = ModulePath.Text.Trim();
                var moduleRemark = ModuleRemark.Text;
                var entity = new Lc_Block
                {
                    C_BLOCK_NAME = moduleName,
                    C_BLOCK_DEPATH = modulePath,
                    REMARK = moduleRemark
                };
                if (lbb.INSERT(entity, CurrentUserName) > 0)
                {
                    IfEdit.Value = "1";
                    lbltitle.InnerText = "模\t块\t编\t辑";
                    MessageBox.Show(this, "【温馨提醒】新增成功");
                }
                else
                {
                    MessageBox.Show(this, "【温馨提醒】新增失败！");
                }
            }
        }
    }
}